//package com.jams.goodox.service;
//
//import android.app.Service;
//import android.content.Intent;
//import android.os.Environment;
//import android.os.IBinder;
//import android.support.annotation.Nullable;
//
//import com.jams.goodox.TownApplicationLike;
//import com.jams.goodox.utils.FileUtil;
//
//import java.io.BufferedInputStream;
//import java.io.File;
//import java.io.FileOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.net.HttpURLConnection;
//import java.net.URL;
//
///**
// * Created by guozhen.hou on 2017/9/19.
// */
//
//public class DownTinkerPatchService extends Service{
//    public static final String TinkerPatchFilePatch= Environment.getExternalStorageDirectory() + File.separator + FileUtil.FILE_DIR + File.separator +"patch";
//    static final String PatchPath = TinkerPatchFilePatch + File.separator + "tinker.patch";//apk路径
//
//    String patchUrl;
//    @Nullable
//    @Override
//    public IBinder onBind(Intent intent) {
//        patchUrl=intent.getStringExtra("patchUrl");
//        return null;
//    }
//
//    @Override
//    public int onStartCommand(Intent intent,int flags, int startId) {
//        downLoadPatch(String.valueOf(patchUrl));
//        return super.onStartCommand(intent, flags, startId);
//    }
//
//    private static void downLoadPatch(final String loadPatchUrl) {
//        FileUtil.getInstance(TownApplicationLike.getInstance()).createFile("/apk");
//        new Thread(new Runnable() {
//            public void run() {
//                InputStream inputStream = null;
//                FileOutputStream outputStream = null;
//                try {
//                    URL url = new URL(loadPatchUrl);
//                    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//                    connection.setConnectTimeout(5000);
//                    int  size = connection.getContentLength();
//                    inputStream = connection.getInputStream();
//                    outputStream = new FileOutputStream(PatchPath);
//                    BufferedInputStream bis = new BufferedInputStream(inputStream);
//                    byte[] buffer = new byte[1024];
//                    int len;
//                    int total = 0;
//                    while ((len = bis.read(buffer)) != -1) {
//                        outputStream.write(buffer, 0, len);
//                        total += len;
//                        if (total == size) {
//                            //TinkerInstaller.onReceiveUpgradePatch(TownApplicationLike.getInstance(), PatchPath);
//                        }
//                    }
//                    inputStream.close();
//                    outputStream.close();
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }finally {
//                    try {
//                        if(outputStream != null)outputStream.close();
//                        if(inputStream != null) inputStream.close();
//                    }catch (IOException e){
//                        e.printStackTrace();
//                    }
//
//                }
//            }
//        }).start();
//    }
//}
